<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>广州市气象台综合业务平台</title>
<base target="_self" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet" type="text/css" />
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<script src="js/excanvas.compiled.js"></script>
<![endif]-->
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="js/swfupload/handlers.js"></script>
</head>

<body>

	<!-- 浏览器 begin -->
    <div id="web-browser" class="hide">
    	<!-- <div class="close-btn"></div> -->
    	
    	<div class="browser-container" id="browser-container">
    		<div class="browser-panel">
    			<div class="browser-title">
    				<span class="title"></span>
    				<div id="browser_titleButtonBar">
    					<a class="close" href="#"></a>
    					<a class="scale" href="#"></a>
    				</div>
    			</div>
    			<!--  
    			<div class="browser-control">
    				<div id="webBrowserBackButton" title="后退" class="control-btn back"> 《 </div>
    				<div id="webBrowserForwardButton" title="前进" class="control-btn forward"> 》</div>
    				<div title="转入" class="control-btn go" id="webBrowserGoButton"> Go </div>
    				<div class="browserAddress">
    					<input type="url" autocorrect="off" id="webBrowserAddressField">
    				</div>
    			</div>
    			-->
    		</div>
    		<iframe id="browser" src="" scrolling="auto"></iframe>
    	</div>
    </div>
    <!-- 浏览器 end -->
	
	<div id="desktop">
    	<!-- 顶部标题 begin -->
        <div id="title-bar">
        	<span>广州市气象台综合业务平台</span>
        	<i></i>
        </div>
        <!-- 顶部标题 end -->
        
        <!-- 左边导航栏 begin -->
        <div id="left-bar">
        	<div id="dockContainer">
        		<div class="menu-lock-btn"><span>隐藏导航条</span></div>
            	<ul class="menu">
                    <?php foreach ($menu as $category): ?>
                    <li>
                    	<a <?php if (!empty($category['url'])): ?>label="<?=$category['url']?>"<?php endif; ?> href="#">
                    		<img width="48" height="48" src="./icon/<?=$category['icon']?>"/>
                            <span><?=$category['name']?></span>
                    	</a>
                    	<?php if (!empty($category['children'])): ?>
                        <div class="sec-menu-area hide">
                        	
                        	<?php foreach ($category['children'] as $subCategory): ?>
                        	<ul class="sec-menu">
                            	<li>
                                	<a href="#" <?php if (!empty($subCategory['url'])): ?>label="<?=$subCategory['url']?>"<?php endif; ?>><?=$subCategory['name']?></a>
                                    <div class="thr-menu-area hide">
                                    	<ul class="thr-menu">
                                    		<?php foreach ($subCategory['children'] as $thirCategory): ?>
                                    		<li><a href="#" label="<?=$thirCategory['url']?>"><?=$thirCategory['name']?></a></li>
                                    		<?php endforeach; ?>
                                    	</ul>  
                                    </div>
                                </li>
                            </ul>
                            <?php endforeach; ?>
                        </div>
                        <?php endif; ?>
                    </li>
                    <?php endforeach; ?>
                    <li class="setting-btn">
                    	<a href="#">
                    		<img src="./images/setting-ico.png"/>
                    	</a>
                    </li>
                </ul>
                <?php if ($userLogin === true && $action == 'user'): ?>
                <div class="logout-btn">登出</div>
                <?php endif; ?>
                <?php if ($isLogin === true && $action == 'admin'): ?>
                <div class="logout-btn">登出</div>
                <?php endif; ?>
            </div>
        </div>
        <!-- 左边导航栏 end -->
        
        <!-- 下方工具条 begin -->
        <div id="bottom-bar">
        	<?php if ($userLogin === false && $action === 'user'): ?>
        	<!-- 登录窗口 begin -->
        	<!-- 
        	<div class="login-panel">
        		<div class="close-btn"></div>
        		<div class="ttl">
        			<h3><span><?php if ($action == 'user'): ?>预报员登录<?php elseif ($action == 'admin'): ?>管理员登录<?php endif; ?></span></h3>
        		</div>
        		<div class="content">
        			<form id="admin-login" action="index.php/admin/login" method="post">
        				<div class="row">
        					<label>用户名:</label>
        					<input type="text" value="" name="username" id="username"  />
        				</div>
        				<div class="row">
        					<label>密&nbsp;&nbsp;码:</label>
        					<input type="password" value="" name="password" id="password" />
        				</div>
        				<div class="row" style="padding-left:100px;">
        					<button style="margin-left:5px;" type="submit"><span>登录</span></button>
        				</div>
        			</form>
        		</div>
        	</div>
        	 -->
        	<div class="login-panel">
        		<div class="close-btn"></div>
        		<div class="ttl">
        			<h3>预报员登录</h3>
        		</div>
        		<div class="content">
        			<form id="admin-login" action="" method="post">
        				<label>用户名:</label>
        				<input id="username" type="text" value="" name="username"  />
        				<label style="margin-left:10px;">密码:</label>
        				<input id="password" type="password" value="" name="password" />
        				<button style="margin-left:5px;" type="submit"><span>登录</span></button>
        			</form>
        		</div>
        	</div> 
        	<!-- 登录窗口 end -->
        	<?php elseif ($isLogin === false && $action === 'admin'): ?>
        	<!-- 登录窗口 begin -->
        	<div class="login-panel">
        		<div class="close-btn"></div>
        		<div class="ttl">
        			<h3>管理员登录</h3>
        		</div>
        		<div class="content">
        			<form id="admin-login" action="" method="post">
        				<label>用户名:</label>
        				<input id="username" type="text" value="" name="username"  />
        				<label style="margin-left:10px;">密码:</label>
        				<input id="password" type="password" value="" name="password" />
        				<button style="margin-left:5px;" type="submit"><span>登录</span></button>
        			</form>
        		</div>
        	</div>
        	<!-- 登录窗口 end -->
        	<?php endif; ?>
        </div>
        <!-- 下方工具条 end -->
        
        <!-- 右边导航栏 begin -->
        <div id="right-bar">
        	<div class="widget-container">
        		<div id="weather">
        		
        			<div id="weather_now_pic"></div>
        			
        			<div id="weather_now_temperature"></div>
        			
        			<a id="weatherWidget_city" href="#" title="广州">广州</a>
        			
        			<div id="weatherWidget_moreInfoPanel">
        				<div id="weatherWidget_time"></div>
        				<div class="weatherWidget_refresh_wrapper">
        					<a id="weatherWidget_refresh">刷新</a>
        				</div>
        			</div>
        		
        		</div>
        		<canvas id="clock" width="200" height="200">
        		<script>
        		var canvas, context;
        		function DrawClock() {
        		    canvas = document.getElementById("clock");
        		    context = canvas.getContext("2d");
        		    setInterval("drawbackground()", 1000);
        		}
        		function drawbackground() {
        		    var radius = Math.min(canvas.width / 2, canvas.height / 2) - 15;
        		    var centerx = canvas.width / 2;
        		    var centery = canvas.height / 2;
        		    context.clearRect(0, 0, canvas.width, canvas.height);
        		    context.save();
        		    context.lineWidth = 10;//环宽度
        		    context.fillStyle = "#EFEFEF";
        		    context.strokeStyle = "#000";
        		    context.beginPath();
        		    context.arc(centerx, centery, radius, 0, Math.PI * 2, 0);
        		    context.fill();
        		    context.stroke();
        		    context.closePath();
        		    context.restore();
        		    for (var i = 0; i < 60; i++) {
        		        context.save();
        		        context.fillStyle = "#EFEFEF";
        		        context.strokeStyle = "#000";   
        		        if (i % 5 == 0) {
        		            context.lineWidth = 3;//时刻度
        		        }
        		        context.beginPath();
        		        context.moveTo(centerx, centery);
        		        context.lineTo(centerx + (radius-6) * Math.cos(i * 6 * Math.PI / 180), centery - (radius-5) * Math.sin(i * 6 * Math.PI / 180));
        		        context.fill();
        		        context.stroke();
        		        context.closePath();
        		        context.restore();
        		    }
        		    context.moveTo(centerx, centery);
        		    context.save();
        		    context.fillStyle = "#EFEFEF";
        		    context.strokeStyle = "#EFEFEF";
        		    context.beginPath();
        		    context.arc(centerx, centery, radius-15, 0, Math.PI * 2, 0);
        		    context.fill();
        		    context.stroke();
        		    context.closePath();
        		    context.restore();

        		    var r = radius - 25;
        			/*
        		    Drawtext("1", centerx + (Math.cos(60 * Math.PI / 180) * r), centery - (Math.sin(60 * Math.PI / 180) * r));
        		    Drawtext("2", centerx + (Math.cos(30 * Math.PI / 180) * r), centery - (Math.sin(30 * Math.PI / 180) * r));
        		    Drawtext("3", centerx + (Math.cos(0 * Math.PI / 180) * r), centery - (Math.sin(0 * Math.PI / 180) * r));
        		    Drawtext("4", centerx + (Math.cos(330 * Math.PI / 180) * r), centery - (Math.sin(330 * Math.PI / 180) * r));
        		    Drawtext("5", centerx + (Math.cos(300 * Math.PI / 180) * r), centery - (Math.sin(300 * Math.PI / 180) * r));
        		    Drawtext("6", centerx + (Math.cos(270 * Math.PI / 180) * r), centery - (Math.sin(270 * Math.PI / 180) * r));
        		    Drawtext("7", centerx + (Math.cos(240 * Math.PI / 180) * r), centery - (Math.sin(240 * Math.PI / 180) * r));
        		    Drawtext("8", centerx + (Math.cos(210 * Math.PI / 180) * r), centery - (Math.sin(210 * Math.PI / 180) * r));
        		    Drawtext("9", centerx + (Math.cos(180 * Math.PI / 180) * r), centery - (Math.sin(180 * Math.PI / 180) * r));
        		    Drawtext("10", centerx + (Math.cos(150 * Math.PI / 180) * r), centery - (Math.sin(150 * Math.PI / 180) * r));
        		    Drawtext("11", centerx + (Math.cos(120 * Math.PI / 180) * r), centery - (Math.sin(120 * Math.PI / 180) * r));
        		    Drawtext("12", centerx + (Math.cos(90 * Math.PI / 180) * r), centery - (Math.sin(90 * Math.PI / 180) * r));
        			*/
        		    context.save();
        		    context.fillStyle="black";
        		    context.beginPath();
        		    context.arc(centerx,centery,10,0,Math.PI*2,0);
        		    context.fill();
        		    context.stroke();
        		    context.closePath();
        		    context.restore();

        		    drawpoint(centerx, centery, radius);

        		}

        		function drawpoint(centerx, centery, radius) {
        		    var date = new Date();
        		    var h = date.getHours();
        		    h = h < 13 ? h : h - 12;
        		    var m = date.getMinutes();
        		    var s = date.getSeconds();

        		    var th = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        		    var tm = m < 10 ? "0" + m : m;
        		    var ts = s < 10 ? "0" + s : s;
        		    //document.getElementById("currtime").innerHTML = th + ":" + tm + ":" + ts;

        		    var hr = h * 30 * Math.PI / 180 + (m / 60) * 30 * Math.PI / 180 + 90 * Math.PI / 180;
        		    var mr = m * 6 * Math.PI / 180 + s / 60 * 6 * Math.PI / 180 + 90 * Math.PI / 180;
        		    var sr = s * 6 * Math.PI / 180 + 90 * Math.PI / 180;
        		    context.save();
        		    context.lineWidth = 5;//针宽度
        		    context.fillStyle = "darkgray";
        		    context.strokeStyle = "black";
        		    context.beginPath();
        		    context.moveTo(centerx + 20 * Math.cos(hr), centery + 20 * Math.sin(hr));
        		    context.lineTo(centerx - (radius - 50) * Math.cos(hr), centery - (radius - 50) * Math.sin(hr));//时针

        		    context.moveTo(centerx + 20 * Math.cos(mr), centery + 20 * Math.sin(mr));
        		    context.lineTo(centerx - (radius - 30) * Math.cos(mr), centery - (radius - 30) * Math.sin(mr));//分针


        		    context.moveTo(centerx + 20 * Math.cos(sr), centery + 20 * Math.sin(sr));
        		    context.lineTo(centerx - (radius - 20) * Math.cos(sr), centery - (radius - 20) * Math.sin(sr));//秒针

        		    context.closePath();
        		    context.fill();
        		    context.stroke();
        		    context.restore();
        		}

        		function Drawtext(text, x, y) {
        		    context.save();
        		    x -= (context.measureText(text).width / 2);
        		    y += 9;
        		    context.beginPath();
        		    context.translate(x, y);
        		    context.fillText(text, 0, 0);
        		    context.restore();
        		}

        		window.onload = DrawClock; 
    			</script>
        	</div>
        </div>
        <!-- 右边导航栏 end -->
        
        
        
    </div>
    
    
    
    <script type="text/javascript">
		$(document).ready(function() {
			//swfupload配置
			var swfu;
			swfu = new SWFUpload({
				upload_url: "index.php/admin/uploadIcon",
				file_size_limit : "2 MB",
				file_types : "*.jpg;*.png;*.gif;",
				file_types_description : "JPG Images; PNG Image; GIF Image;",
				file_upload_limit : 0,
				/*
				swfupload_preload_handler : preLoad,
				swfupload_load_failed_handler : loadFailed,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_complete_handler : uploadComplete,
				upload_success_handler : uploadSuccessEx,
				file_queue_error_handler:fileQueueError,
				*/
				swfupload_preload_handler : function() {},
				swfupload_load_failed_handler : function() {},
				file_queue_error_handler : function() {},
				file_dialog_complete_handler : fileDialogComplete,
				upload_progress_handler : function() {},
				upload_error_handler : function() {},
				upload_complete_handler : uploadComplete,
				upload_success_handler : uploadSuccessEx,
				file_queue_error_handler:fileQueueError,
				button_width:55,
				button_height: 22,
				button_text:'<span class="swf-button">上传图标</span>',
				button_text_style : '.swf-button{background:#F0F0F0}',
				button_text_top_padding: 0,
				button_text_left_padding: 0,
				button_placeholder_id: "swf-btn",
				button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
				button_cursor: SWFUpload.CURSOR.HAND,
				flash_url : "js/swfupload/swfupload.swf",
				flash9_url: "js/swfupload/swfupload_fp9.swf",
				debug: false
			});

			/* 上传成功 */
			function uploadSuccessEx (file, serverData) {
				try {
					//alert(serverData);
        			var json = $.parseJSON(serverData);
        			$("#edit-dialog input[name='icon']").val(json.fileName);
        		} catch (ex) {
        			//this.debug(ex);
        		}
			}

			//左边工具条显隐藏
			var lockLeftBar = true;
			//$('#dockContainer').animate({left:'-96px'}, 'slow');
			$('#left-bar').hover(function() {
				if (!lockLeftBar) {
					$('#dockContainer').animate({left:'0px'}, 'slow');
				}
			},
			function() {
				if (!lockLeftBar) {
					$('#dockContainer').animate({left:'-96px'}, 'slow');
					$('#left-bar #dockContainer .menu li').removeClass('hover');
				}
			});

			//锁定左边工具条
			$('#dockContainer .menu-lock-btn').click(function() {
				if (!lockLeftBar) {
					lockLeftBar = true;
					$('#dockContainer .menu-lock-btn span').html('隐藏导航条');
				}
				else {
					lockLeftBar = false;
					$('#dockContainer .menu-lock-btn span').html('显示导航条');
				}
			});

			//浏览器可调整大小
			$('#web-browser').resizable({disabled:true});

			//隐藏右键菜单
			document.oncontextmenu = function() {return false;};

			//调整左边导航条位置
			function fitLeftbarPosition() {
				var outerHeight = $('#left-bar').outerHeight();
				var containerHeight = $('#dockContainer').outerHeight();
				if (outerHeight < containerHeight) {
					$('#dockContainer').css({top:'0px'});
				}
				else {
					var topValue = (outerHeight - containerHeight) / 2;
					$('#dockContainer').css({top:topValue});
				}
			}
			fitLeftbarPosition();
			$(window).resize(function() {
				fitLeftbarPosition();
			});
			
			//点击空白处隐藏菜单
			$('#desktop').click(function() {
				//alert('123');
				$('#left-bar #dockContainer .menu li').removeClass('hover');
				if ($('#bottom-bar .tool-container li')) {
					$('#bottom-bar .tool-container li').removeClass('hover');
				}
			});

			//浏览器缩小
			var browserScale = true;
			$('#web-browser #browser_titleButtonBar a.scale').click(function() {
				var browserDom = $('#web-browser');
				if (!browserScale) {
					browserDom.css({width:'70%', 'height':'70%'});
					//$('#browser').css({width:'50%', 'height':'50%'});
					$('#browser-container').css({width:'100%', 'height':'100%'});
					browserScale = true;
					$('#web-browser').draggable({disabled: false});
					var iframeHeight = ($(window).height()) * 0.7 - 25;
					//alert((iframeHeight - 25) + 'px');
					$('#browser').css({width:'100%', 'height':(iframeHeight) + 'px'});
					$('#web-browser').resizable({disabled:false,
						resize: function(event, ui) {
							var browserHeight = $('#web-browser').outerHeight();
							$('#browser').css({width:'100%', 'height':(browserHeight - 25) + 'px'});
					}});
				}
				else {
					browserDom.css({width:'100%', 'height':'100%', 'top':'0px', left:'0px'});
					var browserHeight = $(window).height() - 25;
					$('#browser').css({width:'100%', 'height':browserHeight + 'px'});
					$('#browser-container').css({width:'100%', 'height':'100%'});
					browserScale = false;
					$('#web-browser').draggable({disabled: true});
					$('#web-browser').resizable({disabled:true});
				}
			});
			
			//设置小工具可拖拉
			$('#weather').draggable();
			$('#clock').draggable();
			$('#web-browser').draggable();

			//天气小工具，刷新天气
			$('#weather #weatherWidget_refresh').click(function() {
				$.ajax({
					type:'get',
					dataType:'json',
					url:'index.php/widget/weather/',
					success:function(data) {
						var icoUrl = 'http://cache.soso.com/zdq/tb/day/' + data.now_pic;
						var temperature = data.now_temperature;
						var labelTime = data.update_time;

						$('#weather #weather_now_pic').css({'background-image':'url(' + icoUrl + ')'});
						$('#weather #weather_now_temperature').html(temperature + '°C');
						$('#weather #weatherWidget_time').html('更新时间' + labelTime);
					}
				});
			});
			$('#weather #weatherWidget_refresh').trigger('click');
			
			//载入之前选择的壁纸
			var wallpapersUrl = getCookie('wallpapers');
			if (wallpapersUrl) {
				$('#desktop').css({background:'center center url(' + wallpapersUrl +')'});
			}
			
			//染色
			$('#bottom-bar .tool-fir-menu > li').eq(0).children('span').children('a.rai-btn').addClass('pink-btn');
			$('#bottom-bar .tool-fir-menu > li').eq(1).children('span').children('a.rai-btn').addClass('green-btn');
			$('#bottom-bar .tool-fir-menu > li').eq(2).children('span').children('a.rai-btn').addClass('blue-btn');
			
			//第一级菜单事件
			$('#left-bar #dockContainer .menu > li').click(function(event) {
				$('#left-bar #dockContainer .menu > li').removeClass('hover');
				$(this).addClass('hover');

				var url = $(this).children('a').attr('label');
				if (url) {
					$('#web-browser').removeClass('hide').addClass('show');
					$('#browser').attr('src', url);
					$('#left-bar #dockContainer .menu li').removeClass('hover');
					$('#webBrowserAddressField').val(url);
				}
				
				event.stopPropagation();
				
			});
			
			//第二级菜单事件
			$('#left-bar #dockContainer .sec-menu > li').click(function(event) {
				$('#left-bar #dockContainer .sec-menu > li').removeClass('hover');
				$(this).addClass('hover');

				var url = $(this).children('a').attr('label');
				if (url) {
					$('#web-browser').removeClass('hide').addClass('show');
					$('#browser').attr('src', url);
					$('#left-bar #dockContainer .menu li').removeClass('hover');
					$('#webBrowserAddressField').val(url);
					
				}
				
				event.stopPropagation();
			});
			
			//第三级菜单事件
			$('#left-bar #dockContainer .thr-menu > li a').click(function(event) {
				var url = $(this).attr('label');
				//先显示iframe的浏览窗口
				$('#web-browser').removeClass('hide').addClass('show');
				$('#browser').attr('src', url);
				$('#left-bar #dockContainer .menu li').removeClass('hover');
				$('#webBrowserAddressField').val(url);
				
				event.stopPropagation();//阻止事件冒泡
			});
			
			//内部浏览器关闭按钮
			$('#web-browser .browser-container .browser-panel .browser-title #browser_titleButtonBar a.close').click(function() {
				$('#web-browser').removeClass('show').addClass('hide');
			});

			//内部浏览器Go按钮
			$('#webBrowserGoButton').click(function() {
				var url = $('#webBrowserAddressField').val();
				if (!url.match('http://')) {
					url = 'http://' + url;
				}
				if (url == '') return;
				$('#browser').attr('src', url);
			});

			//内部浏览器后退按钮
			$('#webBrowserBackButton').click(function() {
				var frames = document.getElementById('browser').contentWindow;
				frames.history.back();
				$('#webBrowserAddressField').val('');
			});

			//内部浏览器前进按钮
			$('#webBrowserForwardButton').click(function() {
				var frames = document.getElementById('browser').contentWindow;
				frames.history.forward();
				$('#webBrowserAddressField').val('');
			});
			
			//设置内部浏览器在中间
			function fitBrowserPosition() {
				var windowWidth = $(window).width();
				var webBrowserWidth = $('#web-browser').width();
				var leftOffset = (windowWidth - webBrowserWidth) / 2;
				//leftOffset = leftOffset -20;
				$('#web-browser').css({left:(leftOffset-80) + 'px', width:1039 + (leftOffset+80) + 'px'});
				$('#browser-container').css({width:1000+ (leftOffset+80) + 'px'});
				//var iframeHeight = $('#browser').outerHeight;
				iframeHeight = $(window).height() - 25;
				$('#browser').css({width:1000+ (leftOffset+80) + 'px', height:iframeHeight + 'px'});
			}
			fitBrowserPosition();
			
			//下方按钮一级菜单
			$('#bottom-bar .tool-container .tool-fir-menu > li').click(function(event) {
				$('#bottom-bar .tool-container .tool-fir-menu > li').removeClass('hover');
				$(this).addClass('hover');
				//fitBottomMenuWidth('#bottom-bar .tool-container .tool-fir-menu .tool-sec-menu');
				//alert($(this).children('.tool-sec-menu'));
				fitBottomMenuWidth($(this).children('.tool-sec-menu'));
				fitBottomMenuPositon($(this), '#bottom-bar .tool-container .tool-fir-menu > li .tool-sec-menu');
				event.stopPropagation();
			});
			
			//下方二级按钮
			$('#bottom-bar .tool-container .tool-fir-menu .tool-sec-menu > li').click(function(event) {
				$('#bottom-bar .tool-container .tool-fir-menu .tool-sec-menu > li').removeClass('hover');
				$(this).addClass('hover');

				var url = $(this).children('a').attr('label');
				if (url) {
					$('#web-browser').removeClass('hide').addClass('show');
					$('#browser').attr('src', url);
					$('#bottom-bar .tool-container li').removeClass('hover');
					$('#webBrowserAddressField').val(url);
				}
				
				//fitBottomMenuWidth('#bottom-bar .tool-container .tool-fir-menu .tool-sec-menu .tool-thr-menu');
				fitBottomMenuWidth($(this).children('.tool-thr-menu'));
				fitBottomMenuPositon($(this), '#bottom-bar .tool-container .tool-fir-menu .tool-sec-menu > li .tool-thr-menu');
				event.stopPropagation();//阻止事件冒泡
			});
			
			//下方三级按钮
			$('#bottom-bar .tool-container .tool-fir-menu .tool-sec-menu .tool-thr-menu > li').click(function (event) {
				var url = $(this).children('a').attr('label');
				//alert(url);
				$('#web-browser').removeClass('hide').addClass('show');
				$('#browser').attr('src', url);
				$('#webBrowserAddressField').val(url);
				$('#bottom-bar .tool-container li').removeClass('hover');
				event.stopPropagation();//阻止事件冒泡
			});
			
			//调整下方菜单宽度
			function fitBottomMenuWidth(selector) {
				//alert(selector.children('li').length);
				//var elementWidth = $(selector + ' > li').outerWidth();
				//var elementLength = $(selector + ' > li').length;
				var elementWidth = selector.children('li').outerWidth();
				var elementLength = selector.children('li').length;
				var menuWidth = elementWidth * elementLength;
				$(selector).css({width:menuWidth + 'px'});
			}
			
			//调整下方菜单位置
			function fitBottomMenuPositon(refElement, operElement) {
				var refElementOffset = refElement.offset();
				var refElementWidth = refElement.width();
				var operElementWidth = $(operElement).width();
				var leftOffset = (refElementWidth / 2) - (operElementWidth / 2);
				$(operElement).css({left:leftOffset + 'px'});
			}
			
			//设置-弹出窗
			$('#left-bar .setting-btn').unbind('click');
			$(document).ready(function () {
				
				$('#setting-dialog').dialog({
					autoOpen: false,
					resizable:false,
					minWidth:555,
					maxWidth:555
				});
				<?php if ($action == 'user' || $isLogin === true): ?>
				$('#left-bar .setting-btn').click(function() {
					$('#setting-dialog').dialog( "open" );
					return false;
				});
				<?php elseif ($action == 'admin' && $isLogin === false): ?>
				$('#left-bar .setting-btn').click(function() {
					$('.login-panel').show();
					alert('请先登录');
					return false;
				});
				<?php endif; ?>
			});
			
			//设置-弹出窗，切换
			$('#setting-dialog .toggle-bar span').click(function() {
				var index = $(this).index();
				$('#setting-dialog .content .num').hide();
				$('#setting-dialog .content .num-' + index).show();
				
				$('#setting-dialog .toggle-bar span').removeClass('activ');
				$(this).addClass('activ');
			});
			
			//小部件设置-天气
			$('#weather-button').click(function() {
				if ($(this).attr('checked')) {
					$('#weather').show();
				}
				else {
					$('#weather').hide();
				}
			});
			
			//小部件设置-时钟
			$('#clock-button').click(function() {
				if ($(this).attr('checked')) {
					$('#clock').show();
				}
				else {
					$('#clock').hide();
				}
			});
			
			//设置壁纸
			$('#setting-dialog .content .wallpapers li').click(function() {
				var dataDom = $(this).children('img');
				var url = dataDom.attr('src');
				$('#desktop').css({background:'center center url(./' + url +')'});

				//存为cookie
				setCookie('wallpapers', './' + url, 7, '/');
			});

			//设置远端壁纸
			$('#setting-dialog .content .item-body .set-remote-bg button').click(function() {
				var url = $('#remote-image-url').val();
				$('#desktop').css({background:'center center url(' + url +')'});

				//存为cookie
				setCookie('wallpapers', url, 7, '/');
			});

			//关闭登录窗口
			$('.login-panel .close-btn').click(function() {
				$('#bottom-bar .login-panel').hide();
			});

			//关闭按钮动画
			$('.login-panel .close-btn').hover(function() {
				$(this).css({'background-position':'bottom center'});
			},
			function() {
				$(this).css({'background-position':'top center'});
			});
			
			//管理员登录
			$('#admin-login').submit(function() {
				var usernameVal = $('#username').val();
				var passwordVal = $('#password').val();
				$.ajax({
					type:'post',
					<?php if ($action == 'user'): ?>
					url:'index.php/admin/userLogin',
					<?php elseif ($action == 'admin'): ?>
					url:'index.php/admin/login',
					<?php endif; ?>
					dataType:'json',
					data:{username:usernameVal, password:passwordVal},
					success:function(json) {
						
						var code = json.code;
						var msg = json.msg;
						if (code == 0) {
							location.reload();
						}
						else {
							alert(msg);
						}
					}
				})
				return false;
			});

			//登出
			$('#dockContainer .logout-btn').click(function() {
				$.ajax({
					type:'get',
					<?php if ($action == 'user'): ?>
					url:'index.php/admin/userLogout',
					<?php elseif ($action == 'admin'): ?>
					url:'index.php/admin/logout',
					<?php endif; ?>
					dataType:'json',
					success:function(json) {
						location.reload();
					}
				});
			});
			
			//编辑操作
			$('#setting-dialog .content span.action a.edit').live('click', function () {
				var id = $(this).attr('label');
				var name = '';
				var icon = '';
				var parentId = 0;
				var url = '';
				var isShow = 1;
				$.ajax({
					type:'get',
					url:'index.php/admin/queryMenu?id=' + id,
					dataType:'json',
					success:function(json) {
						if (json.code != 0) {
							alert('错误！没有你要编辑的项目。');
							return;
						}
						else {
							name = json.msg.name;
							parentId = json.msg.parent_id;
							parentName = json.msg.parent_name;
							icon = json.msg.icon;
							url = json.msg.url;
							isShow = json.msg.is_show;
							
							//填充表单
							$("#edit-dialog input[name='name']").val(name);
							//$("#edit-dialog input[name='parent_id']").val(parentId);
							if (parentId != 0) {
								$("#edit-dialog select[name='parent_id']").html('<option value="' + parentId + '">' + parentName + '</option>');
							}
							$("#edit-dialog input[name='icon']").val(icon);
							$("#edit-dialog input[name='url']").val(url);
							$("#edit-dialog select[name='is_show']").children("option").attr('selected', null);
							$("#edit-dialog select[name='is_show']").children("option[value='" + isShow + "']").attr('selected', '');
							$("#edit-dialog input[name='action']").val('edit');
							$("#edit-dialog input[name='id']").val(id);
							$("#edit-dialog select[name='parent_id']").bind('click', selectParentMenu);//绑定选择子菜单事件
							$('#edit-dialog').dialog("open");
						}
					}
				});
			});

			//选择上一级菜单
			$("#edit-dialog select[name='parent_id']").click(selectParentMenu);

			function selectParentMenu() {
				var id = $("#edit-dialog input[name='id']").val();
				$.ajax({
					type:'get',
					dataType:'json',
					url:'index.php/admin/getMenuList?id=' + id,
					success:function(json) {
						var template = '<option value="0">无</option>';
						$.each(json, function(k, v) {
							template += '<option value="' + v.id + '">';
							template += v.name;
							template += '</option>';
						});
						$("#edit-dialog select[name='parent_id']").html('');
						$("#edit-dialog select[name='parent_id']").append(template);
					}
				});
				$(this).unbind('click');
			}

			//删除操作
			$('#setting-dialog .content span.action a.delete').live('click', function() {
				var id = $(this).attr('label');
				$.ajax({
					type:'get',
					dataType:'json',
					url:'index.php/admin/delMenu',
					data:{delId:id},
					success:function(json) {
						if (json.code!=0) {
							alert(json.msg);
						}
						else {
							//删除项目
							alert(json.msg);

							var id = json.delId;
							$("#setting-dialog .content .item-body .row[label='" + id + "']").detach();
						}
					}
				});
			});
			
			//添加操作
			$('#add-menu').click(function() {
				$("#edit-dialog input[name='action']").val('add');
				//清空表单
				$("#edit-dialog input[name='name']").val('');
				$("#edit-dialog input[name='icon']").val('');
				//$("#edit-dialog input[name='parent_id']").val(0);
				$("#edit-dialog select[name='parent_id']").html('<option value="0">无</option>');
				$("#edit-dialog input[name='url']").val('');
				$("#edit-dialog input[name='id']").val(0);
				$("#edit-dialog select[name='is_show']").children("option").attr('selected', null);
				$("#edit-dialog select[name='is_show']").children("option[value='1']").attr('selected', '');
				$("#edit-dialog select[name='parent_id']").bind('click', selectParentMenu);//绑定选择子菜单事件
				//打开
				$('#edit-dialog').dialog("open");
			});
			
			//编辑框
			$('#edit-dialog').dialog({
				autoOpen:false,
				resizable:false,
				minWidth:555,
				maxWidth:555,
				buttons: { 
						"Ok": function() {
							//获取表单数据
							var editId = $("#edit-dialog input[name='id']").val();
							var formAction = $("#edit-dialog input[name='action']").val();
							var editName = $("#edit-dialog input[name='name']").val();
							var editIcon = $("#edit-dialog input[name='icon']").val();
							var editParentId = $("#edit-dialog select[name='parent_id'] option:selected").val();
							var editUrl = $("#edit-dialog input[name='url']").val();
							var editIsShow = $("#edit-dialog select[name='is_show'] option:selected").val();
							//alert(editIsShow);
							$.ajax({
								type:'post',
								dataType:'json',
								url:'index.php/admin/processMenuFrom',
								data:{id:editId, 
									action:formAction, 
									name:editName, 
									parent_id:editParentId,
									url:editUrl,
									icon:editIcon,
									is_show:editIsShow},
								success:function(json) {
									if (json.code != 0) {
										alert(json.msg);
										return;
									}
									$(this).dialog("close");
									alert('成功!');
									
									//修改列表
									if (json.action == 'edit') {
										var id = json.msg.id;
										var dom = $("#setting-dialog .row[label='" + id + "']");
										dom.children('span.parent-id').html(json.msg.parent_id);
										dom.children('span.name').html(json.msg.name);
										dom.children('span.url').html(json.msg.url);
										dom.children('span.is-show').html(json.msg.is_show);
										dom.children('span.action').children('a').attr(json.msg.id);
									}
									
									//增加列表项
									if (json.action == 'add') {
										var temp = '';
										temp += '<div class="row" label="' + json.msg.id + '">';
										temp += '<span class="id">' + json.msg.id + '</span>';
										temp += '<span class="parent-id">' + json.msg.parent_id + '</span>';
										temp += '<span class="name">' + json.msg.name + '</span>';
										temp += '<span class="url">' + json.msg.url + '</span>';
										temp += '<span class="is-show">' + json.msg.is_show + '</span>';
										temp += '<span class="action"><a class="edit" href="#" label="' + json.msg.id + '">编辑</a> <a class="delete" href="#" label="' + json.msg.id + '">删除</a></span>';
										temp += '</div>';
										$('#setting-dialog .content .item-body').append(temp);
									}
								}
							});
						},
						"Cancel": function() {$(this).dialog("close");} 
						}
			});


			//未登录点击预报制作重新弹出登录框
			<?php if ($userLogin != true): ?>
			var loginBtn = $('#dockContainer .menu li.setting-btn').prev('li');
			loginBtn.unbind('click');
			loginBtn.click(function() {
				$('.login-panel').show();
				alert('请先登录');
			});
			<?php endif; ?>
		});
	</script>
	
	<!-- 设置弹出窗 begin -->
	<div id="setting-dialog" class="setting-dialog" title="设置">
		<div class="toggle-bar">
			<span class="activ">系统主题</span>
			<span>自定义</span>
			<?php if ($isLogin === true && $action == 'admin'): ?>
			<span>管理员</span>
			<?php endif; ?>
		</div>
		<div class="content">
			<div class="num-0 num">
				<div class="item-body">
					<div class="row set-remote-bg">
					<label>远程图片:</label>
					<input type="text" value="" name="remote-image-url" id="remote-image-url" />
					<button><span>OK</span></button>
					</div>
				</div>
				<ul class="wallpapers">
					<?php foreach ($wallpapers as $item): ?>
					<li>
						<img src="<?=$item['url']?>" width="145" height="91"/>
						<a href="#"><?=$item['name']?></a>
					</li>
					<?php endforeach; ?>
				</ul>
			</div>
			
			<div class="num-1 num hide">
				<div class="item-title">桌面小部件设置</div>
				<div class="item-body">
					<input type="checkbox" checked="checked" id="weather-button" /><label for="weather-button">今日天气</label>
					<input type="checkbox" checked="checked" id="clock-button" /><label for="clock-button">时钟</label>
				</div>
			</div>
			<?php if ($isLogin === true && $action == 'admin'): ?>
			<div class="num-2 num hide">
			<div class="item-title">菜单设置</div>
			<div class="add-bar"><a id="add-menu" href="#">添加菜单</a></div>
			<div class="item-body">
				<div class="row">
					<span class="id">编号</span>
					<span class="parent-id">上级菜单编号</span>
					<span class="name">名称</span>
					<span class="url">地址</span>
					<span class="is-show">是否显示</span>
					<span class="action">操作</span>
				</div>
				<?php foreach ($adminMenu as $row): ?>
				<div label="<?=$row['id']?>" class="row">
					<span class="id"><?=$row['id']?></span>
					<span class="parent-id"><?=$row['parent_id']?></span>
					<span class="name"><?=$row['name']?></span>
					<span class="url"><?=$row['url']?></span>
					<span class="is-show"><?=$row['is_show']?></span>
					<span class="action">
						<a class="edit" label="<?=$row['id']?>" href="#">编辑</a>
						<a class="delete" label="<?=$row['id']?>" href="#">删除</a>
					</span>
				</div>
				<?php endforeach; ?>
			</div>
			<?php endif; ?>
		</div>
	</div>
	<!-- 设置弹出窗 end -->
	
	<!-- 菜单编辑窗 begin -->
	<div id="edit-dialog" class="edit-dialog" title="操作">
		<div class="content">
			<form id="editMenu" method="post">
				<div class="row">
					<span>名称:</span><input type="text" name="name" value="" />
				</div>
				<div class="row">
					<span>上级菜单:</span>
					<select name="parent_id" style="width:207px;">
						<option value="0">无</option>
					</select>
				</div>
				<div class="row">
					<span>图标:</span><input disabled="disabled" type="text" name="icon" value="" />
					<div id="swf-btn"></div>
				</div>
				<div class="row">
					<span>地址:</span><input type="text" name="url" value="" />
				</div>
				<div class="row">
					<span>是否显示:</span><select name="is_show"><option value="1">是</option><option value="0">否</option></select>
				</div>
				<input type="hidden" name="action" value="" />
				<input type="hidden" name="id" value="0" />
			</form>
		</div>
	</div>
	<!-- 菜单编辑窗 end -->
	
</body>
</html>
